package com.shi.entity.po;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.shi.entity.vo.AccountVO;
import com.shi.properties.SysProperties;
import com.shi.util.SpringUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * (Account)实体类
 *
 * @author makejava
 * @since 2024-05-16 17:18:00
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("account")
public class Account implements Serializable {
    private static final long serialVersionUID = -75108872583683137L;
    /**
     * 用户id
     */
    @TableId(type = IdType.AUTO)
    private Integer uid;
    /**
     * 用户名
     */
    private String username;
    /**
     * 密码
     */
    private String password;
    /**
     * 昵称
     */
    private String nickname;
    /**
     * 头像
     */
    private String avatar;

    /**
     * 邮箱
     */
    private String email;
    /**
     * 上次登录时间
     */
    private Date lastLoginTime;
    /**
     * 创建时间
     */
    private Date createTime;

    public static List<AccountVO> toAccountVOList(List<Account> accountList) {
        SysProperties sysProperties = SpringUtil.getBean(SysProperties.class);
        List<String> sysAdminList = sysProperties.getSysAdminList();
        return accountList.stream().map(item -> {
            AccountVO accountVO = BeanUtil.toBean(item, AccountVO.class);
            if (sysAdminList.contains(accountVO.getUsername())) {
                accountVO.setAdmin(true);
            }
            return accountVO;
        }).toList();
    }

}

